home *** CD-ROM | disk | FTP | other *** search
- class Point2D
- {
- var x = 0;
- var y = 0;
- var rotation = 0;
- function Point2D(sx, sy, srot)
- {
- this.x = sx;
- this.y = sy;
- this.rotation = srot;
- }
- static function polar(len, angle)
- {
- var _loc1_ = new Point2D();
- _loc1_.x = len * Math.cos(angle);
- _loc1_.y = len * Math.sin(angle);
- return _loc1_;
- }
- function clone()
- {
- var _loc2_ = new Point2D(this.x,this.y,this.rotation);
- return _loc2_;
- }
- function dotProduct(op)
- {
- return this.x * op.x + this.y * op.y;
- }
- function normalize()
- {
- if(Math.abs(this.x) > Math.abs(this.y))
- {
- this.y /= Math.abs(this.x);
- this.x /= Math.abs(this.x);
- }
- else
- {
- this.x /= Math.abs(this.y);
- this.y /= Math.abs(this.y);
- }
- }
- function subtract(p)
- {
- var _loc2_ = new Point2D(this.x - p.x,this.y - p.y,this.rotation - p.rotation);
- return _loc2_;
- }
- function multiply(factor)
- {
- return new Point2D(this.x * factor,this.y * factor,this.rotation);
- }
- function getLength()
- {
- var _loc2_ = new Point2D(Math.abs(this.x),Math.abs(this.y));
- return Math.sqrt(this.x * this.x + this.y * this.y);
- }
- function toString()
- {
- return "(" + this.x + "," + this.y + ")";
- }
- function getDirection()
- {
- return Math.atan2(this.x,- this.y) / 3.141592653589793 * 180;
- }
- }
-